home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
cenvid
/
autoload.cmm
< prev
next >
Wrap
Text File
|
1995-10-11
|
14KB
|
486 lines
/*
* Autoload.cmm
*
* This file handles most of the shell interface of CEnvi. The rest of the
* interface is included as the file "ShellChr.cmm". This version will run
* on all CEnvi systems known as of the revision date.
*
*/
if( !defined(_NWNLM_) && !defined(_DOS_) && !defined(_DOS32_) && !defined(_OS2_) &&
!defined(_WINDOWS_) && !defined(_NTCON_) && !defined(_NTWIN_) )
{
printf("\nThe system you are running CEnvi on is not supported by this\n"
"version of AUTOLOAD.CMM. A newer version should have been included\n"
"in your distribution. You should use that instead.\n");
exit(1);
}
if( !defined(_SHELL_) )
{
printf("Autoload.cmm is an internal shell implementation file and cannot be\n");
printf("run as a program.\n");
exit(EXIT_FAILURE);
}
/* ---------------------------------------------------------------------- */
// First we have a list of commands that are to be passed on directly to
// the shell. Windows and Netware have no such list of commands.
if( defined(_DOS_) || defined(_DOS32_) )
{
SystemCommands =
{
"DIR", "COPY", "MKDIR", "MD", "RMDIR",
"RD", "ERASE", "DEL", "TYPE", "ECHO"
};
}
else if( defined(_OS2_) )
{
SystemCommands =
{
"DIR", "MKDIR", "MD", "RMDIR", "RD",
"ERASE", "DEL", "TYPE", "START", "DETACH",
"COPY", "ECHO"
};
}
else if( defined(_NTCON_) )
{
SystemCommands =
{
"DIR", "COPY", "MKDIR", "MD", "RMDIR",
"RD", "ERASE", "DEL", "TYPE", "ECHO",
"START"
};
}
if( defined(SystemCommands) ) qsort(SystemCommands,"stricmp");
// Some Basic Aliases
alias_list = {
{ "md", "makedir" },
{ "mkdir", "makedir" },
{ "clear", "cls" },
{ "erase", "del" },
{ "rm", "del" },
{ "cp", "copy" },
{ "mv", "move" },
{ "ren", "move" },
{ "rename", "move" },
{ "chmod", "attrib" },
{ "rd", "rmdir" },
{ "load", "start" }
};
if ( defined(_DOS_) || defined(_DOS32_) ) {
// spawning can leave too-little memory, so increase COMSPEC size
if ( !defined(COMSPEC_ENV_SIZE) )
COMSPEC_ENV_SIZE = 2000;
}
///////////////////////////////////////////////////////////////////////
#include "CmdLine.lib"
// The other systems all have this defined. Netware has no Environment variables
// so we define it here.
if( defined(_NWNLM_) ) PROMPT = NULL;
if ( !defined(_WINDOWS_) && !defined(_NTWIN_)
&& defined(PROMPT) && strnicmp("[CEnvi]",PROMPT,7) )
{
strcpy(oldprompt,PROMPT);
sprintf(PROMPT,"[CEnvi] %s",PROMPT);
getenv();
}
/*
* Change the current directory to the given one. Return 0 if successful.
*/
my_chdir(newdir)
{
if( defined(_NWNLM_) ) return chdir(newdir);
if( defined(_DOS_) || defined(_DOS32_) || defined(_WINDOWS_) )
{
lReg.ah = 0x3B;
if ( !defined(_DOS32_) )
lReg.ds = segment(newdir), lReg.dx = offset(newdir);
else
lReg.dx = pointer(newdir);
interrupt(0x21,lReg,out);
return out.ax==3;
}
if( defined(_NTCON_) || defined(_NTWIN_) )
{
return !DynamicLink("KERNEL32","SetCurrentDirectoryA",STDCALL,newdir);
}
if( defined(_OS2_) )
{
#define ORD_DOS32SETCURRENTDIR 255
return DynamicLink("doscalls",ORD_DOS32SETCURRENTDIR,BIT32,CDECL,newdir);
}
}
//**************************************************************************
//****** BEGIN SECTION TO HANDLE INTERNAL COMMANDS FOR THE CLI SHELL *******
//**************************************************************************
// Next is a list of all commands handled internally to the shell. This list
// must remain sorted. Also, the InternalHelp array must match. It is fortunate
// that currently all the 'extra' commands only defined on certain systems
// fall later than any other command in the alphabet.
InternalCommands = {
"ALIAS", "CD", "CHDIR", "CLS", "ECHO", "HELP", "PROMPT", "PWD"
};
InternalHelp = {
"The ALIAS command lets you view or define aliases. ALIAS by itself will list\n"
"all aliases currently defined. Otherwise define an alias by using the format:\n"
"\n ALIAS name=text string",
"CD used by itself will print the current directory. If you give it a\ndirectory name, it will change the current directory to it.",
"CHDIR changes the current directory to the given directory.",
"CLS clears the screen.",
"ECHO prints some text to the screen.",
"HELP by itself prints all known commands, otherwise it prints help on a command.",
"PROMPT will change the prompt. By itself, it resets the prompt to the default.",
"PWD will print the current working directory.",
};
if( defined(_DOS_) || defined(_DOS32_) || defined(_WINDOWS_) || defined(_NTCON_) ||
defined(_NTWIN_) || defined(_OS2_) )
{
InternalCommands[GetArraySpan(InternalCommands)+1] = "SET";
InternalHelp[GetArraySpan(InternalHelp)+1] =
"SET allows you to view or change environment variables. SET by itself will\n"
"list all such variables currently defined. Otherwise define one by using the\n"
"format:\n\n"
" SET variable=value";
}
if( defined(_WINDOWS_) || defined(_NTWIN_) || defined(_NWNLM_) )
{
InternalCommands[GetArraySpan(InternalCommands)+1] = "START";
InternalCommands[GetArraySpan(InternalCommands)+1] = "TYPE";
InternalHelp[GetArraySpan(InternalHelp)+1] =
"START starts an Executable or NLM running asynchronously.";
InternalHelp[GetArraySpan(InternalHelp)+1] =
"TYPE will echo the contents of a file to the screen.";
}
// set up filter to handle each command input
ShellFilterCommand("AutoloadFilterCommand");
AutoloadFilterCommand(pCommand)
{
if ( !stricmp(pCommand,"EXIT") )
{
if( defined(oldprompt) ) PROMPT = oldprompt;
} else {
strcpy(tmp,pCommand);
s = strchr(tmp,' ');
if( s ) s[0] = '\0';
if ( !stricmp(SplitFileName(tmp).name,"autoload") )
{
printf("Autoload.cmm is an internal shell implementation file and cannot be\n");
printf("run as a program.\n");
pCommand[0] = '\0';
} else {
strcpy(command,pCommand); pCommand[0] = '\0';
ProcessCommandLine(command,"AutoloadFilterExecutor");
}
}
}
AutoloadFilterExecutor(pCommand)
{
lResult = EXIT_SUCCESS;
undefine(alias);
alias = "";
for( i=0;pCommand[i];i++ )
{
if( isspace(pCommand[i]) ) break;
alias[i] = pCommand[i];
}
the_rest = "";
strcpy(the_rest,pCommand+i);
alias[i] = 0;
for( j=0;j<=GetArraySpan(alias_list);j++ )
{
if( !stricmp(alias,alias_list[j][0]) )
{
pCommand = "";
strcpy(pCommand,alias_list[j][1]);
strcat(pCommand,the_rest);
break;
}
}
// if line starts with a quote, it is cmm code to execute immediately.
if ( strchr("\"\'`",pCommand[0]) ) {
if( pCommand[strlen(pCommand)-1]==pCommand[0] )
pCommand[strlen(pCommand)-1] = 0;
lResult = interpret(pCommand+1,INTERP_TEXT|INTERP_NOINHERIT_GLOBAL|
INTERP_NOINHERIT_LOCAL);
pCommand[0] = 0;
}
// if command found in SystemCommands list then execute it immediately
// with CMD.EXE then, else check internal cmds and some others
else if ( 1 == sscanf(pCommand,"%s",lCommand) ) {
if( defined(SystemCommands) && bsearch(lCommand,SystemCommands,"stricmp") )
{
strcpy(command,pCommand); pCommand[0] = '\0'
if( defined(_OS2_) || defined(_NTCON_) || defined(_NTWIN_) )
{
lResult = spawn(P_WAIT,"CMD.EXE","/C",command);
}
else if( defined(_DOS_) || defined(_DOS32_) )
{
lResult = system(P_SWAP,command);
}
} else if ( bsearch(lCommand,InternalCommands,"stricmp") ) {
sprintf(lInternalFunction,"InternalCommand_